package com.hc.dfs.task;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.hc.dfs.entities.flow.UnsignedNode;
import com.hc.dfs.entities.mobile.DocumentDetail;
import com.hc.dfs.service.common.Page;
import com.hc.dfs.service.common.ParamsTable;
import com.hc.dfs.service.internet.Service;

public class DoTaskMethod {

	// 网络数据交互服务
	public Service service = new Service();
	// 保存公文详情
	public static DocumentDetail documentDetail;
	// 保存公文列表（根据参数可能是待签、跟踪、待办）
	public static List<UnsignedNode> documentList = new ArrayList<UnsignedNode>();

	/**
	 * 根据类型获取公文列表
	 * 
	 * @param type
	 * @return
	 */
	public ArrayList<HashMap<String, Object>> getDocumentList(int type) {
		// 数据查询参数（一页10条）
		Page p = new Page();
		p.setPage(1);
		p.setPageSize(10);
		// 传递消息和数据(此处获取数据的接口应该还有一个type参数，用类判断返回给documentList的数据是待签、跟踪还是待办)
		documentList = service.getServiceApi().getUnsignedNodes(61, p);
		if (documentList != null) {
			// 定义新的ArrayList
			ArrayList<HashMap<String, Object>> itemList = new ArrayList<HashMap<String, Object>>();
			for (UnsignedNode doc : documentList) {
				HashMap<String, Object> map = new HashMap<String, Object>();
				// 公文类型id
				int docType = doc.getDocument().getDocTypeId();
				// 公文日期
				Date date = doc.getDocument().getSaveTime();
				SimpleDateFormat df = new SimpleDateFormat(
						"yyyy-MM-dd HH:mm:ss");
				String d = df.format(date);
				// 添加数据
				map.put("title", doc.getDocument().getTitle());
				map.put("date", d);
				map.put("huanji", ParamsTable.convertPriorityLevel(doc
						.getDocument().getPriorityLevel()));
				map.put("miji", ParamsTable.convertConfidenceLevel(doc
						.getDocument().getConfidenceLevel()));
				map.put("leixing", "[" + ParamsTable.getDocType(docType) + "]");
				map.put("docId", doc.getDocument().getId());
				map.put("docType", docType);
				System.out.println("得到的标题是：" + map.get("title"));
				itemList.add(map);
			}
			return itemList;
		}
		return null;
	}

	/**
	 * 根据公文id获取公文详情
	 * 
	 * @param docId
	 *            公文id
	 * @return
	 */
	public HashMap<String, String> getDocumentDetail(int docId) {

		// 请求网络数据
		documentDetail = service.getServiceApi().getDocumentDetail(docId);
		if (documentDetail != null) {
			HashMap<String, String> docDetail = new HashMap<String, String>();
			int docType = documentDetail.getDocTypeId();
			// 三种类型公共数据
			SimpleDateFormat df = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm:ss");
			String date = df.format(documentDetail.getSaveTime());
			docDetail.put("docType", ParamsTable.getDocType(docType));
			docDetail.put("title", documentDetail.getTitle());
			docDetail.put("serialNum", documentDetail.getSerialNum());
			docDetail.put("priorityLevel", ParamsTable.getPriorityLevel(documentDetail.getPriorityLevel()));
			docDetail.put("confidenceLevel", ParamsTable.getConfidenceLevel(documentDetail.getConfidenceLevel()));
			docDetail.put("reporterName",documentDetail.getReporterName());
			docDetail.put("saveTime", date);
			//特定类型数据填充
			switch (docType) {
			case 4:
				//无额外内容
				break;
			case 5:
				//发文稿额外内容
				docDetail.put("sendTo", documentDetail.getSendTo());
				docDetail.put("reportTo", documentDetail.getReportTo());
				docDetail.put("copyTo", documentDetail.getCopyTo());
				docDetail.put("drafterName", documentDetail.getDrafterName());
				break;
			case 6:
				//合同额外内容
				docDetail.put("phone", documentDetail.getPhone());
				docDetail.put("mainParties", documentDetail.getMainParties());
				docDetail.put("otherParties", documentDetail.getOtherParties());
				docDetail.put("monitorName", documentDetail.getMonitorName());
				docDetail.put("contractAmount", documentDetail.getContractAmount());
				docDetail.put("verifyIdentityCard", ParamsTable.getBooleanSwitch(documentDetail.getVerifyIdentityCard()));
				docDetail.put("verifyOtherCard", ParamsTable.getBooleanSwitch(documentDetail.getVerifyOtherCard()));
				docDetail.put("contractContent", documentDetail.getContractContent());
				break;

			default:
				break;
			}
			return docDetail;
		}
		return null;
	}
}
